/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.vojna.ant_alg.tests;

import java.io.File;
import pl.vojna.ant_alg.Problem;
import pl.vojna.ant_alg.Utils;
import pl.vojna.ant_alg.algorithms.AntSystemLocalSearch;
import pl.vojna.ant_alg.algorithms.RandomSearch;
import pl.vojna.ant_alg.lokal_search_alg.TabuSearch;

/**
 *
 * @author rusak
 */
public class AntSystemTest {

    /**
     * Testy pochodza z QAPlib, korzystam z ich oznaczen.
     * 
     * @param args
     */
    public static void main(String[] args) {
       runTest("chr12a", 9552, "opt, 100k+50k");
        runTest("chr12b", 9742, "opt, 100k+50k");
        runTest("chr12c", 11156, "opt, 100k+50k");
        runTest("chr15a", 9896, "opt, 100k+50k");
        runTest("chr15b", 7990, "opt, 100k+50k");
        runTest("chr15c", 9504, "opt, 100k+50k");
        runTest("chr18a", 11098, "opt, 100k+50k");
        runTest("chr18b", 1534, "opt, 100k+50k");
        runTest("chr20a", 2192, "opt, 100k+50k");
        runTest("chr20b", 2298, "opt, 100k+50k");
        runTest("chr20c", 14142, "opt, 100k+50k");
        
        /*
         //tutaj lepiej niż random and tabu
        runTest("bur26a", 5426670, "opt, 100k+50k");
        runTest("bur26b", 3817852, "opt, 100k+50k");
        runTest("bur26c", 5426795, "opt, 100k+50k");
        runTest("bur26d", 3821225, "opt, 100k+50k");
        runTest("bur26e", 5386879, "opt, 100k+50k");
        runTest("bur26f", 3782044, "opt, 100k+50k");
        runTest("bur26g", 10117172, "opt, 100k+50k");
        runTest("bur26h", 7098658, "opt, 100k+50k");
        */
        /*
         // te wszystkie na maksa
        runTest("esc16a", 68, "opt, 100k+50k");
        runTest("esc16b", 292, "opt, 100k+50k");
        runTest("esc16c", 160, "opt, 100k+50k");
        runTest("esc16d", 16, "opt, 100k+50k");
        runTest("esc16e", 28, "opt, 100k+50k");
        runTest("esc16f", 0, "opt, 100k+50k");
        runTest("esc16g", 26, "opt, 100k+50k");
        runTest("esc16h", 996, "opt, 100k+50k");
        runTest("esc16i", 14, "opt, 100k+50k");
        runTest("esc16j", 8, "opt, 100k+50k");
        runTest("esc16j", 8, "opt, 100k+50k");
        runTest("esc32e", 2, "opt, 100k+50k");
        runTest("esc32g", 6, "opt, 100k+50k");
        */
        //te duze sa
       /*
         runTest("lipa60a", 107218, "opt, 100k+50k");
         runTest("lipa60b", 2520135, "opt, 100k+50k");
         runTest("lipa70a", 169755, "opt, 100k+50k");
         runTest("lipa70b", 4603200, "opt, 100k+50k");
         runTest("lipa80a", 253195, "opt, 100k+50k");
         runTest("lipa80b", 7763962, "opt, 100k+50k");
         runTest("lipa90a", 360630, "opt, 100k+50k");
         runTest("lipa90b", 12490441, "opt, 100k+50k");
         */
    }

    private static void runTest(String filename, int bestSolution,
            String description) {
        int popSize = 20;
        String description2 = "pF = 2; hF = 1; pV = 0.2; pS = 10000";
        double pheromoneFactor = 2;
        double heuristicFactor = 1;
        double pheromoneVanish = 0.3;
        double pheromoneStrength = 10000;
        int ASIterations = 7;
        Problem p = new Problem(new File("data/" + filename + ".dat"));
         AntSystemLocalSearch antSystem = new AntSystemLocalSearch(
                heuristicFactor, pheromoneFactor, pheromoneVanish,
                pheromoneStrength);
      /* int[] s2 = new RandomSearch().solve(p, 0, false, 100000);
	s2 = new TabuSearch().improve(s2, p, 50000);*/
        int s1[] = antSystem.solve(p, popSize, Boolean.FALSE,ASIterations);
        Utils.showSolution(s1);
        Utils.p("AntSystemLocalSearch", filename, Utils.solutionCost(p, s1),
                bestSolution + " " + description2);
      /*  Utils.p("Random+TabuSearch", filename, Utils.solutionCost(p, s2),
				bestSolution + " " + description);*/
        
        System.out.println();
    }
}
